/**
 * 
 */
package com.alkandros.linesmash.ui;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.alkandros.linesmash.R;
import com.alkandros.linesmash.constants.AppConstants;
import com.alkandros.linesmash.location.ILocationCallBack;

/**
 * @author Jiju Induchoodan
 *
 */
public class ActionSelection  extends BaseActivity implements OnClickListener,ILocationCallBack{

	private boolean isSignedIn=false;
	private LinearLayout linearSignin;
	private RelativeLayout linearThree;
	private RelativeLayout relativeLocation;
	private LinearLayout linearOne;
	private RelativeLayout dining;
	private RelativeLayout events;
	private Intent intent;
	private boolean isNewActivity=false;
	private EditText edtLocation;
	private ImageButton btnGps;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_action_selection);
		Bundle extras= getIntent().getExtras();
		Log.e("", "create");
		if(extras!=null)
		{
			isSignedIn  = extras.getBoolean("signed_in");
		}
		setHeading(R.string.action_selection_heading);
	    setLeftButton();
	    setRightButton();
	    initialiseUI();
	}
	
	private void initialiseUI()
	{
		relativeLocation	  = (RelativeLayout)findViewById(R.id.relative_location);
		linearSignin   		  = (LinearLayout)findViewById(R.id.linear_two);
		linearOne	   		  = (LinearLayout)findViewById(R.id.linear_one);
		linearThree	   		  = (RelativeLayout)findViewById(R.id.relative_three);
		dining	   	   		  = (RelativeLayout)findViewById(R.id.relative_dining);
		events                = (RelativeLayout)findViewById(R.id.relative_events);
		edtLocation			  = (EditText)findViewById(R.id.edt_location);
		btnGps				  = (ImageButton)findViewById(R.id.btn_gps);
		if(isSignedIn)
		{
			linearSignin.setVisibility(View.VISIBLE);
			relativeLocation.setVisibility(View.VISIBLE);
		}
		
			
		
		linearThree.setVisibility(View.GONE);
		
		dining.setOnClickListener(this);
	//	events.setOnClickListener(this);
		btnGps.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) 
	{
		if(v==dining)
		{
			isNewActivity =true;
			intent = new Intent(ActionSelection.this,VenuesPage.class);
			startActivity(intent);
			
		}
		else if(v==events)
		{
			isNewActivity =true;
			intent = new Intent(ActionSelection.this,VenuesPage.class);
			startActivity(intent);
		}
		else if(v==btnGps)
		{
			if(gps.canGetLocation())
			{
                AppConstants.APP_LATITUDE = gps.getLatitude();
                AppConstants.APP_LONGITUDE = gps.getLongitude();
                edtLocation.setText(gps.getCompleteAddressString(AppConstants.APP_LATITUDE,  AppConstants.APP_LONGITUDE));
            }
			else
			{
                gps.showSettingsAlert();
            }
		}
	}
	@Override
	protected void onPause() {
		super.onPause();
		if(isNewActivity)
		{
			
		}
	}
	@Override
	protected void onResume() {
		super.onResume();
		Log.e("", "Resume");
		if(isSignedIn)
		{
			linearSignin.setVisibility(View.VISIBLE);
		}
		else
		{
			linearSignin.setVisibility(View.INVISIBLE);
		}
	}

	@Override
	public void setResult(String address) {
		edtLocation.setText(address);
		
	}
}
